#ifndef __tenacitas_text_log_file_merger__merger__h__
#define __tenacitas_text_log_file_merger__merger__h__



/** @file */


/** @todo Add to tenacitas::balance_line::merger a 'stop reading file' policy */

// ==> C++ Headers
#include <string>
#include <memory>
#include <list>

// ==> 3rds Headers


// ==> Our Headers

// ==> Namespaces
using namespace std;

// ==> Macro Constants

// ==> Macro Commands


/** ==> namespace of the organization */
namespace tenacitas {
    /** ==> namespace for the project */
    namespace text_log_file_merger {

        // ==> Typedefs 

        // ==> Pre-Declarations

        // ==> Attributes 

        // ==> Functions
        
        // ==> Classes

        /** Merges text log files generated by tenacitas::log::text_file
           
            @nosubgrouping 
        */
        class merger {

        public:

            // ==> merger - Public Internal Types

            // ==> merger - Public Constructors

            /** Destructor */
            ~merger( );

            // ==> merger - Public Accessors

            // ==> merger - Public Helpers

            // ==> merger - Public Processors

            /** */
            void start( ) {
                /*
                  for every file in dir do
                       if file ends in log.END then
                           if file in list of unfinished log ( lul ) then
                               retrieve offset 
                               open file
                               seek to offset
                               remove from lul
                           else
                               open file
                           end-if
                       else if file ends in .log
                           if file in lul then
                               retrieve offset 
                               open file
                               seek to offset
                           else
                               open file
                               insert file into lul
                           end-if
                      end-if
                      add file to be merged
                  end-for
                  merge
                  delete all log.END files
                */
            }
            

            // ==> merger - Public Operators

            // ==> merger - Public Attributes

        private:

            // ==> merger - Private Internal Types

            /** 

                @nosubgrouping 
            */
            class file {

                // ==> file - Friends

            public:

                // ==> file - Public Internal Types

                /** ptr type */
                typedef std::shared_ptr<file> ptr;

                // ==> file - Public Constructors

                /** Destructor */
                ~file( );

                // ==> file - Public Accessors

                // ==> file - Public Helpers

                // ==> file - Public Processors

                // ==> file - Public Operators

                // ==> file - Public Attributes

            private:

                // ==> file - Private Internal Types

                // ==> file - Private Constructors

                // ==> file - Private Accessors

                // ==> file - Private Helpers

                // ==> file - Private Processors

                // ==> file - Private Operators

                // ==> file - Private Attributes

                /** */
                std::string m_path;

                /** next reading offset */
                uint64_t m_offset;

            };

            /** 

                @nosubgrouping 
            */
            class files {

                // ==> files - Friends

            public:

                // ==> files - Public Internal Types

                // ==> files - Public Constructors

                /** Destructor */
                ~files( );

                // ==> files - Public Accessors

                /** Adds a file into the list */
                void add( const std::string & p_file_name );

                /** Tries to find a @p file based on a file name */
                file::ptr find( const std::string & p_file_name );

                // ==> files - Public Helpers

                // ==> files - Public Processors

                // ==> files - Public Operators

                // ==> files - Public Attributes
            private:

                // ==> files - Private Internal Types

                // ==> files - Private Constructors

                // ==> files - Private Accessors

                // ==> files - Private Helpers

                // ==> files - Private Processors

                /** Loads the list of files */
                void load( );

                // ==> files - Private Operators

                // ==> files - Private Attributes

            };



            // ==> merger - Private Constructors

            // ==> merger - Private Accessors

            // ==> merger - Private Helpers

            // ==> merger - Private Processors

            // ==> merger - Private Operators

            // ==> merger - Private Attributes
        };
    }
}

// =============================================================================
// I M P L E M E N T A T I O N
// =============================================================================

using namespace tenacitas::text_log_file_merger;


#endif
